" 9999" | .compareTo | ("023") | negative |
"(rat)" | .compareTo | ("[cat]") | negative |
"23.5" | .compareTo | ("23,7") | positive |
"More Cheese?" | .compareTo | ("More Cheese!") | positive |
"cobol" | .compareTo | ("cobalt") | positive |
The elements of an ordered array are arranged in ascending (or descending) order.
The picture shows an array of ints
arranged into ascending order.
The array can have duplicate elements.
The elements of an array can be arranged in order by using a static sort()
method
of the Arrays
class.
static void sort( array ) // Sort the array into ascending order
There are sort()
methods for arrays of type
byte[], char[], double[], float[], int[],
and long[]
.
There is also a method that can sort object references
based on the values of the objects.
Sorting is an important process in computer programming. Many data processing operations depend on data that is sorted, much as the data in a filing cabinet is kept sorted.
Would a dictionary be useful if its definitions were not in sorted order?